<template>
  <div class="container scopClass" v-if="List.length > 0">

        <!-- <el-row style="margin: 20px 0">
          <el-col :span="7">
            <el-input
              style="border-radius: 0 5px 5px 0; width: 300px"
              placeholder="请输入关键词"
              v-model.trim="searchName1"
            >
              <i slot="prefix" class="el-input__icon el-icon-search"></i>
              <el-button slot="append" @click="handleSearch1">搜索</el-button>
            </el-input>
          </el-col>
          <el-button
            type="primary"
            @click="newAdd"
            style="float: right; margin-right: 10px"
            >新增</el-button
          >
        </el-row> -->
        <el-row style="margin:20px 0;">
            <el-col :span="7">
                <el-input style="border-radius: 0 5px 5px 0;width:300px;" placeholder="请输入关键词"  v-model.trim="searchName1">
                    <i slot="prefix" class="el-input__icon el-icon-search"></i>
                    <el-button slot="append" @click="handleSearch1">搜索</el-button>
                </el-input>
            </el-col>



        </el-row>
        <el-table
          :data="tableData"
          border
          ref="multipleTable"
          header-cell-class-name="table-header"
        >
          <el-table-column prop="" sortable label="标识分类" >
            <template slot-scope="scope">
              <span v-if="scope.row.fromFactoryName !== null">{{scope.row.fromFactoryName}}</span>
              <span v-else>{{scope.row.factoryName}}</span>
            </template>
          </el-table-column>
          <!-- <el-table-column prop="factoryName" sortable label="标识分类" ></el-table-column> -->
          <el-table-column prop="inventoryType" sortable label="产品大类"></el-table-column>
          <el-table-column prop="breedName" sortable label="名称"></el-table-column>
          <!-- <el-table-column prop="loadingQuantity" sortable label="装量"></el-table-column>
          <el-table-column prop="loadingUnits" sortable label="包装"></el-table-column> -->
          <el-table-column prop="ypCodeStandard" sortable label="药品标识码标准"></el-table-column>
          <el-table-column label="销售备案号" width="150" align="center">
            <template slot-scope="scope">
              <el-button
                type="text"
        		style="color:#606266;"
                @click="handleCheck(scope.$index, scope.row)"
                >查看</el-button
              >
            </template>
          </el-table-column>
          <el-table-column prop="createTime" sortable label="添加修改时间"></el-table-column>

          <el-table-column label="操作" width="150" align="center">
            <template slot-scope="scope">
              <el-button
                type="text"
                @click="handleEdit(scope.$index, scope.row)"
                >编辑</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          layout="total, prev, pager, next, jumper"
          :page-size="pagesize1"
          @current-change="handleCurrentChange1"
          :total="total1"
          :current-page.sync="currentPage1"
          style="margin-top: 20px"
        ></el-pagination>
     <el-dialog title="销售备案号" :visible.sync="dialogFormVisible1">
         <el-table
           :data="tableData1"
           border
           ref="multipleTable"
           header-cell-class-name="table-header"
         >

           <el-table-column prop="address" sortable label="地域名称"></el-table-column>
           <el-table-column prop="recordCode" sortable label="销售备案号"></el-table-column>

         </el-table>
         <div slot="footer" class="dialog-footer">
             <el-button @click="dialogFormVisible1 = false">关 闭</el-button>
             <!-- <el-button type="primary" @click="submitForm1('ruleForm1')">确 定</el-button> -->
         </div>
     </el-dialog>
  </div>
</template>

<script>
import axios from "axios";
import { materialBreed_list, materialBreed_delete } from "@/request/api";
import {
  materials_import,
  template_findByCompanyId as templateFindByCompanyId,
  materialBreed_findByLis as materialBreedFindByLis,
} from "@/request/manageapi";
import uploadFile from "../../../common/uploadfile";
export default {
  props: ["activeName1"],
  components: {
    uploadFile,
  },
  data() {
    return {
      tableData: [],
      total1: 0,
      currentPage1: 1,
      pagesize1: 10,
      activeName: "",
      searchName1: "",
      List: [],
	  dialogFormVisible1:false
    };
  },
  async created() {
    // if(localStorage.getItem('ListData')){
    //   localStorage.removeItem('ListData')
    // }else{
    //   return true
    // }
    await this.init();
    await this.materialBreedFindByLis();
    // var data = JSON.stringify(this.$store.state.wl);
    // var a = "新增";
    // var b = "编辑";
  },
  mounted() {},
  destroyed: function () {
    this.$store.commit("setStorName", "");
  },
  methods: {
	  // 打开销售备案号弹窗
	    handleCheck(index,row){
	  	  this.dialogFormVisible1 = true
	  	  if(row.sellRecord){
	  		  this.tableData1 = JSON.parse(row.sellRecord)
	  	  }

	    },
	  // 调用接口
	  // init() {
	  //   // let companyId = this.activeName1;
	  //   let companyId = localStorage.getItem("companyId")
	  //   return new Promise((resolve, reject) => {
	  //     templateFindByCompanyId(`?companyId=${companyId}&&isNew=1`)
	  //       .then((res) => {
	  //         this.List = res.data;
	  //         if (this.List.length > 0) {
	  //           this.activeName = this.List[0].templateName;
	  //         }
	  //         resolve(res);
	  //       })
	  //       .catch((err) => {
	  //         reject(err);
	  //       });
	  //   });
	  // },
    // 调用接口
    init() {
      let companyId = this.activeName1;
      return new Promise((resolve, reject) => {
        templateFindByCompanyId(`?companyId=${companyId}&&isNew=1`)
          .then((res) => {
            this.List = res.data;
            if (this.List.length > 0) {
              this.activeName = this.List[0].templateName;
            }
            resolve(res);
          })
          .catch((err) => {
            reject(err);
          });
      });
    },
    materialBreedFindByLis() {
      let companyId = this.activeName1;
      let materialType = "配方颗粒";
      let inventoryType = "C60中药配方颗粒,C70中药配方颗粒";
      let page = this.currentPage1;
      let searchName = this.searchName1
      let data = {
        companyId,
        materialType,
        inventoryType,
        page,
      		searchName
      };
      return new Promise((resolve, reject) => {
        materialBreedFindByLis(data).then((res) => {
          if (res.code == 200) {
            this.total1 = res.total
            let tableData = res.rows;
            this.tableData = JSON.parse(JSON.stringify(tableData));
      			for(var i=0;i<this.tableData.length;i++){
      				if(this.tableData[i].ypCodeStandard == 1){
      					this.tableData[i].ypCodeStandard = "国标"
      				}else if(this.tableData[i].ypCodeStandard == 2){
      					this.tableData[i].ypCodeStandard = "省标"
      				}else if(this.tableData[i].ypCodeStandard == 3){
      					this.tableData[i].ypCodeStandard = "省标-北京"
      				}else if(this.tableData[i].ypCodeStandard == 4){
      					this.tableData[i].ypCodeStandard = "省标-上海"
      				}
      			}
          }
          resolve(res);
        });
      });
    },
    handleSearch1() {},
    // tabs
    async handleClick(tab, event) {
      this.currentPage1 = 1
      await this.materialBreedFindByLis();
    },
    // 编辑
    handleEdit(index, row) {
      // let ListData = JSON.stringify(row)
      // localStorage.setItem('ListData',ListData)
      this.$router.push({
        path:"/managerecord/add",
        query:{
          id:row.id
        }
      });
    },
    // 分页事件
    async handleCurrentChange1(val) {
      this.currentPage1 = val;
      await this.materialBreedFindByLis();
    },
  },
  watch: {
    activeName1: {
      async handler(newVal, oldVal) {
        this.activeName1 = newVal;
        await this.init();
        await this.materialBreedFindByLis();
      },
      deep: true,
    },
  },
};
</script>

<style lang="less" scoped>
// 深度作用器
/deep/.upload-daoru {
  .el-upload {
    border: none;
    width: auto;
    height: auto;
    border-radius: 0;
    float: right;
    margin-right: 10px;
  }
}
.el-col {
  margin-bottom: 0;
}
/* .scopClass .el-table{ margin-top: 20px;} */
.el-pagination {
  text-align: center;
}
/*
.el-select .el-input {
width: 130px;
}
.input-with-select .el-input-group__prepend {
background-color: #fff;
}
.el-input--small .el-input__inner{
    border-radius: 5px 0 0 5px !important;
    border-right: none;
} */
</style>
